#include"List.h"




void init_list(list*phead)
{
	phead->next = phead;
	phead->prev = phead;
	phead->data = 0;

}
void destory_list(list*phead)
{
	list*cur = phead;
	while (cur)
	{
		list*next = cur->next;
		free(cur);
		cur = next;

	}

}
list* create_node(datatype a)
{
	 list* new_node = (list*)malloc(sizeof(list));
	 new_node->data = a;
	 new_node->next = NULL;
	 new_node->prev = NULL;
	 return new_node;
}


void insert_list(list*position, datatype data)
{
	assert(position);
	list*newNode = create_node(data);
	position->prev->next = newNode;
	newNode->prev = position->prev;
	newNode->next = position;
	position->prev = newNode;
}

list* find_list(list*phead, datatype data)
{
	list*cur = phead->next;
	while (cur != phead)
	{
		if (cur->data == data)
			return cur;
		cur = cur->next;
	}
	return NULL;


}


void print_list(list*phead)
{
	list*cur = phead->next;
	while (cur!=phead)
	{
		printf("%d\n", cur->data);
		cur = cur->next;
	}
}
void erase_list(list*position)
{
	assert(position->next != position->prev);
	position->next->prev = position->prev;
	position->prev->next = position->next;
	free(position);
}